package ga.base;

import ga.operadores.selecao.RouletteFitness;
import problema.Solucao;

public class Individuo extends Solucao{
	private RouletteFitness rouletteFitness;

	public Individuo(double[] gene){
		this.variaveis = gene;
		rouletteFitness = null;
	}

	/**
	 * @return the gene
	 */
	public double[] getGene() {
		return variaveis;
	}
	/**
	 * @param gene the gene to set
	 */
	public void setGene(double[] gene) {
		this.variaveis = gene;
	}
	/**
	 * @return the fitness
	 */
	public double getFitness() {
		return fitness;
	}
	/**
	 * @param fitness the fitness to set
	 */
	public void setFitness(double fitness) {
		this.fitness = fitness;
	}

	public RouletteFitness getRouletteFitness() {
		return rouletteFitness;
	}

	public void setRouletteFitness(RouletteFitness rouletteFitness) {
		this.rouletteFitness = rouletteFitness;
	}
	
	@Override
	public int compareTo(Solucao solucao) {
		Individuo individuo = (Individuo)solucao;
		if(rouletteFitness == null){
			if(fitness < individuo.getFitness()){
				return -1;
			}
			else if(fitness > individuo.getFitness()){
				return 1;
			}
			return 0;
		}else{
			if(rouletteFitness.getPercOfFitness() < individuo.getRouletteFitness().getPercOfFitness()){
				return -1;
			}
			else if(rouletteFitness.getPercOfFitness() > individuo.getRouletteFitness().getPercOfFitness()){
				return 1;
			}
			return 0;
		}
	}
}
